<template>
  <el-menu
      :default-active="this.def_url"
      router
      background-color="#28333E"
      text-color="#fff"
  >
    <el-submenu :index="menu.id+''" v-for="(menu,index) in menus">
      <template slot="title">
        <i :class="menus_icon[index]"></i>
        <span>{{menu.name}}</span>
      </template>
      <el-menu-item :index="son_menu.url+''" @click="handleMenuItemClick(son_menu.url)" v-for="son_menu in menu.son_menus">
        <template slot="title">
          <i class="el-icon-s-promotion"></i>
          <span>{{son_menu.name}}</span>
        </template>
      </el-menu-item>
    </el-submenu>
  </el-menu>
</template>

<script>
export default {
  name: "Aside",

  data(){
    return {
      def_url:"borrow_list",
      menus:[],
      menus_icon:["el-icon-s-tools","el-icon-s-data"]
    }
  },

  created() {
    this.getMenus()
    const url = window.sessionStorage.getItem("url")
    if (url){
      this.def_url = url
    }
  },

  methods:{
    handleMenuItemClick(url) {
      if (url!=null&&url!=""){
        window.sessionStorage.setItem("url",url)
      }
    },

    async getMenus() {
      let {data:res} =await this.$axios.get("menus/getMenus")
      this.menus = res.data
    },
  }

}
</script>

<style scoped>
.el-menu{
  width: 100%;
}
</style>